import pandas as pd
from sklearn.metrics import accuracy_score
import joblib
from util.commonUtil import mean_absolute_percentage_error
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import GridSearchCV
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
import transform_test


def tree_predict():
    # 读取数据
    x_test, y_test = transform_test.tes1_do()
    x_test_tree = x_test.iloc[:, 0:20]
    # 模型读取
    model_tree = joblib.load('../model/tree.pkl')

    # 预测概率(用于 ROC AUC)
    y_pred_proba_log = model_tree.predict_proba(x_test_tree)[:, 1]
    # 预测类别（用于准确率）
    y_pred_log = model_tree.predict(x_test_tree)

    auc = roc_auc_score(y_test, y_pred_proba_log)
    accuracy = accuracy_score(y_test, y_pred_log)

    print(f'随机森林准确率: {accuracy:.4f}')
    print(f'随机森林预测值: {y_pred_proba_log}')
    print(f'随机森林AUC值: {auc:.4f}')


if __name__ == '__main__':
    tree_predict()
